//参考文章
//https://zhuanlan.zhihu.com/p/71244491
//https://blog.csdn.net/weixin_43996145/article/details/135250926

char  TESTtable[2];


// 打印不同背景颜色和文本颜色组合的文本信息到SEGGER Real-Time Transfer (RTT)模块
// 使用SEGGER_RTT_printf函数，参数0表示输出到编号为0的终端
// 控制台文本格式控制码由RTT_CTRL_开头的宏定义提供
// 示例：SEGGER_RTT_printf(0, RTT_CTRL_BG_BLACK    "Black background, white text"      RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_BLACK    "Black background, white text"      RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_RED      "Red background, white text"        RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_GREEN    "Green background, white text"      RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_YELLOW   "Yellow background, black text"     RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_BLUE     "Blue background, white text"       RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_MAGENTA  "Magenta background, white text"    RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_CYAN     "Cyan background, white text"       RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_WHITE    "White background, black text"      RTT_CTRL_RESET "\r\n");

	SEGGER_RTT_printf(0, RTT_CTRL_BG_BLACK    "Black background, white font"      RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_BLACK RTT_CTRL_TEXT_BRIGHT_RED    "Red font"        RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_BLACK RTT_CTRL_TEXT_BRIGHT_GREEN  "Bright green font"      RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_BLACK RTT_CTRL_TEXT_YELLOW       "Yellow font"        RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_BLACK RTT_CTRL_TEXT_BRIGHT_BLUE   "Bright blue font"      RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_BLACK RTT_CTRL_TEXT_BRIGHT_MAGENTA "Bright magenta font"    RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_BLACK RTT_CTRL_TEXT_BRIGHT_CYAN    "Bright cyan font"      RTT_CTRL_RESET "\r\n");
	SEGGER_RTT_printf(0, RTT_CTRL_BG_BLACK RTT_CTRL_TEXT_BRIGHT_WHITE   "Bright white font"      RTT_CTRL_RESET "\r\n");


    // 使用SEGGER_RTT_printf函数打印变量cnt的值到SEGGER Real-Time Transfer (RTT)模块
    // 示例：SEGGER_RTT_printf(0, "cnt = %d\n",cnt);
    cnt++;

    int c;
    // 通过SEGGER_RTT_GetKey函数获取用户在调试终端上输入的字符
    c = SEGGER_RTT_GetKey();
    if (c == 'q') {
        // 如果用户输入的字符是'q'，使用SEGGER_RTT_printf函数打印带有白色背景的文本信息到RTT模块
        // 示例：SEGGER_RTT_printf(0, RTT_CTRL_BG_WHITE"scanf q  \n");
    }
    else if (c == 'w') {
        // 如果用户输入的字符是'w'，使用SEGGER_RTT_printf函数打印文本信息到RTT模块
        // 示例：SEGGER_RTT_printf(0, "scanf w  \n");
    }



    // 打印带有颜色和格式控制的文本到RTT模块
    SEGGER_RTT_printf(0, RTT_CTRL_TEXT_BRIGHT_RED "Error: " RTT_CTRL_TEXT_RESET "An error has occurred!\n");

    // 获取用户在调试终端上输入的字符串
    char inputBuffer[64];
    size_t bytesRead = SEGGER_RTT_Read(0, inputBuffer, sizeof(inputBuffer) - 1);
    if (bytesRead > 0) {
        inputBuffer[bytesRead] = '\0';  // 添加字符串结束符
        SEGGER_RTT_printf(0, "User input: %s\n", inputBuffer);
    }

    // 将数据写入RTT中的一个缓冲区
    const char* data = "Some data to be written to RTT\n";
    SEGGER_RTT_Write(0, data, strlen(data));

    // 清空RTT中的输出缓冲区
    SEGGER_RTT_WriteString(0, "\f");  // 发送换页符来清空缓冲区

    // 将RTT输出缓冲区中的内容复制到另一个缓冲区中
    char outputBuffer[128];
    size_t bytesAvailable = SEGGER_RTT_HasData(0);
    if (bytesAvailable > 0) {
        size_t bytesRead = SEGGER_RTT_Read(0, outputBuffer, sizeof(outputBuffer) - 1);
        outputBuffer[bytesRead] = '\0';  // 添加字符串结束符
        // 处理从RTT中读取的数据
    }




    if(SEGGER_RTT_Read(0,TESTtable,2)==2)
    {
        SEGGER_RTT_printf(0, RTT_CTRL_BG_BLACK RTT_CTRL_TEXT_BRIGHT_GREEN   "input table=%s"      RTT_CTRL_RESET "\r\n",TESTtable);

    
    }


